package net.viral.struts2;
import java.sql.*;
public class Connect {

    public Connection connection() {

        Connection con = null;
        String url = "jdbc:mysql://localhost:3306/rss";
       
      //  String db = "IE";
        String driver = "com.mysql.jdbc.Driver";
        String user = "root";
        String pass = "root";
        try {
            Class.forName(driver).newInstance();
            con = DriverManager.getConnection(url, user, pass);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return con;

    }

    public void getUpdate(String query) throws SQLException {
        //System.out.println(query);
         Connection con =null;
         PreparedStatement pst = null;
        try {
        Connect c = new Connect();
        con =c.connection();
        pst=con.prepareStatement(query);
        pst.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public ResultSet getResult(String query) throws SQLException {
       //System.out.println(query);
        ResultSet result = null;
        Statement stmt = null;
         Connection con =null;
        try {
        Connect c = new Connect();
        con =c.connection();

            stmt = con.createStatement();
            result = stmt.executeQuery(query);
           // if(result.next()){
            //	System.out.println(result.getString(1));
            	
          //  }
                
        } catch (Exception e) {
            e.printStackTrace();
        }
         
        return result;
    }
}

